<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>工程首页</h1>
<a href="/reg.html">注册</a>
<a href="/login.html">登录</a>
<h1>异步请求测试</h1>
<a href="/bmi.html">BMI测试</a>
<div>
    <h2>{{info}}</h2>
    <input type="text" v-model="name">
    <input type="button" value="异步get请求" @click="f1()">
    <hr>
    <input type="button" value="异步post请求" @click="f2()">
</div>
<!--引入axios和vue框架文件-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
<script>
    let v = new Vue({
        el:"body>div",
        data:{
            info:"测试异步",name:""
        },
        methods:{
            f1(){
                //发出异步get请求 then里面的匿名方法是服务器响应后触发
                axios.get("/helloAxios?name="+v.name).then(function (response) {
                    //此方法是服务器成功响应之后执行
                    // alert(response.data);
                    v.info = response.data;
                })
            },
            f2(){
                //使用post请求传递多个参数时,将多个参数封装到一个JS对象中
                let data = {username:"tom",password:"123456",nickname:"汤姆"}

                //发出异步post请求
                axios.post("/postAxios",data).then(function (response) {
                    v.info = response.data;
                })
            }
        }
    })
</script>
</body>
</html>